/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package units;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import utils.Handle;


/**
 *
 * @author jamiemacpherson
 */
public class Gene implements Comparable{

    private final int id;
    private String name;
    private String symbol;
    private HashMap<String, String> annots = new HashMap<String, String>();

    private HashMap<String, Object> annotation = new HashMap<String, Object>();


    public Gene(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public Gene(int id) {
        this.id = id;
    }



    public int getId() {
        return id;
    }

    public String getAnnot(String key){
        return annots.get(key);
    }

    public void setAnnot(String key, String value){
        annots.put(key, value);
    }




    @Override
    public boolean equals(Object o){

       return (this.getId()==((Gene)o).getId());

    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 41 * hash + this.id;
        return hash;
    }

    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name;
    }

    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    public String getSymbol() {
        return symbol;
    }

    public HashMap<String, Object> getAnnotation() {
        return annotation;
    }

    public void addAnnotation(String key, Object annot) {
        annotation.put(key, annot);
    }

    public Object getAnnotation(String key) {
        return annotation.get(key);
    }

    public int compareTo(Object o) {
        Gene other = (Gene) o;
        return new Integer(this.getId()).compareTo(new Integer(other.getId()));
    }






     public static String getGeneSymbol(int id, Handle h) {

        String sql = "select symbol from ncbi.gene_info where gId="+id;
        ResultSet rs = h.runSQLquery(sql);
        try {
            if (rs.next()) {
                return rs.getString("symbol");
            } else {
                return "unknown";
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

        return "unknown";
    }








}
